﻿using Customer.API.Applcation.Command.MeetCommand;
using Customer.Infrstructre.Meet;
using MediatR;

namespace Customer.API.Applcation.CommandHandlers.MeetCommandHandler
{
    /// <summary>
    /// 删除应付中介者
    /// </summary>
    public class DelMeetCommandHandler:IRequestHandler<DelMeetCommand,int>
    {
        private readonly IAccountsRepository _accountRep;

        public DelMeetCommandHandler(IAccountsRepository accountRep)
        {
            _accountRep = accountRep;
        }

        public async Task<int> Handle(DelMeetCommand request, CancellationToken cancellationToken)
        {
            var num = 0;
            foreach (var item in request.id)
            {
                var res = (await _accountRep.GetAllAsync()).FirstOrDefault(x => x.AccountsId == item);
                if(res!= null)
                {
                    res.IsDel=true;
                    res.DelName = request.DelName;
                    res.DelTime = request.DelTime;
                    await _accountRep.Update(res);
                    num =1;
                }
                else
                {
                    num=0;
                }
            }
            return num;
        }
    }
}
